from datetime import datetime
from apps.common.utils.decrypt import *

def response_success_notScrypt(data):
    return {
        "code": 10000,
        "data": data,
        "message": "sucess"
    }


def response_success(data):
    # print('success', data)
    return {
        "code": 10000,
        "data": aesEncrypt(AESKey, data),
        "message": "sucess"
    }


def response_error(error):
    print('error', error)
    return {
        "code": 9999,
        "message": error
    }


def response_message(message):
    print('message', message)
    return {
        "code": 8888,
        "message": message
    }


def response_modalMessage(message):
    print('modalMessage', message)
    return {
        "code": 7777,
        "message": message
    }


def response_action(code, data):
    print('action', data)
    return {
        "code": code,
        "message": 'sucess',
        "data": aesEncrypt(AESKey, data)
    }


# 8888 提示错误
# 9999 系统异常


# 1001 配对成功


# 获取请求参数方法
def getRequestParams(request):
    params = {}
    if request.method == "GET" or request.method == "DELETE":
        params = request.query_params.dict()
    elif request.method == "POST" or request.method == "PUT":
        params = aesDecrypt(AESKey, request.data)

        # for value in params.values():
        #     print('key', value, type(value))

    if request.user != 'AnonymousUser':
        if request.user.id:
            params['requestUserId'] = request.user.id
            params['requestUsername'] = request.user.username

    params['channel'] = params.get('channel') if params.get('channel') else request.headers.get('channel')
    params['clientname'] = params.get('clientname') if params.get('clientname') else request.headers.get('clientname')
    print("---------------接收的参数-----------------", params)

    return params


def getRequestParamsNotHeader(request):
    params = {}
    if request.method == "GET" or request.method == "DELETE":
        params = request.query_params.dict()
    elif request.method == "POST" or request.method == "PUT":
        params = aesDecrypt(AESKey, request.data)
    print("----------------接收的参数------------------------", params)

    return params
